package com.dxysun;

import com.dxysun.api.MyApi;

import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;


public class ApiServiceManager
{
//	private static final Map<String, MyApi> MAP = new HashMap<>();
	private static final ApiServiceManager INSTANCE = new ApiServiceManager();
	private final Map<String, MyApi> MAP = new HashMap<>();

	private ApiServiceManager()
	{
		ServiceLoader<MyApi> load = ServiceLoader.load(MyApi.class);

		for (MyApi myApi : load)
		{
			System.out.println("加载 SPI myApi实现类,clazz={} " + myApi.getClass().getName());
			MAP.put(myApi.getClass().getName(), myApi);
		}
	}

	public static ApiServiceManager getInstance()
	{
		return INSTANCE;
	}

	public Map<String, MyApi> getMap()
	{
		return MAP;
	}
	public MyApi getMyApi(String name)
	{
		return MAP.get(name);
	}
}
